from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework.views import APIView
from rest_framework.response import Response

from .models import ImageModel
from ..utils.response_utils import api_response, ResponseCode
from rest_framework import status

class MainServices(APIView):
    """
    主营服务
    """

    @swagger_auto_schema(
        operation_description="主营服务，category传入 1",
        responses={
            200: openapi.Response(
                description="访问成功！",
                schema=openapi.Schema(
                    type=openapi.TYPE_OBJECT,
                    properties={
                        "code": openapi.Schema(type=openapi.TYPE_INTEGER, description="状态码"),
                        "message": openapi.Schema(type=openapi.TYPE_STRING, description="返回信息"),
                        "data": openapi.Schema(
                            type=openapi.TYPE_OBJECT,
                            properties={
                                "images": openapi.Schema(
                                    type=openapi.TYPE_ARRAY,
                                    items=openapi.Schema(
                                        type=openapi.TYPE_OBJECT,
                                        properties={
                                            "name": openapi.Schema(type=openapi.TYPE_STRING, description="图片名称"),
                                            "url": openapi.Schema(type=openapi.TYPE_STRING, description="图片路径"),
                                        }
                                    ),
                                    description="图片列表"
                                ),
                                "description": openapi.Schema(
                                    type=openapi.TYPE_ARRAY,
                                    items=openapi.Schema(
                                        type=openapi.TYPE_OBJECT,
                                        properties={
                                            "headline": openapi.Schema(type=openapi.TYPE_STRING, description="主标题"),
                                            "subheading": openapi.Schema(type=openapi.TYPE_STRING,
                                                                         description="副标题"),
                                            "description": openapi.Schema(type=openapi.TYPE_STRING,
                                                                          description="详细描述", nullable=True),
                                        }
                                    ),
                                    description="描述信息列表"
                                ),
                            }
                        )
                    }
                )
            ),
            500: openapi.Response(description="服务器内部错误")
        },
        tags=["核心业务"]
    )
    def get(self, request, **kwargs):
        try:
            category = kwargs['category']
            images = ImageModel.objects.filter(category=category)
            image_data = [{"name": image.name, "url": image.image_path} for image in images]
            description = [
                    {"headline":"提供TikTok全链路电商解决方案","subheading":"专注于TikTok电商的全链路服务，助力品牌在全球市场实现增长","description":"—选品：基于大数据分析的智能选品策略，精准匹配全球市场消费趋势—供应链管理：智能供应链管理驱动全球高效交付。 —平台运营：TikTok平台生态的精细化运营策略，实现流量高效转化与品牌价值持续提升，构建良性商业闭环。 —品牌推广：全域整合营销驱动品牌全球化高效渗透。"},
                    {"headline":"数据驱动助力品牌全球高效增长","subheading":"通过精准的市场洞察和高效的执行力，帮助品牌在全球市场中快速占领市场实现业绩增长"},
                    {"headline":"高质量原创内容驱动品效双增","subheading":"自有300平方米专业拍摄中心和先进的内容创作团队，生产高质量原创内容，助力品牌实现社交声量与电商转化的双重增长，构建可持续的内容营销生态"},
                    {"headline":"打造高互动性、强传播力的优质内容","subheading":"市场趋势+用户洞察的内容创作，打造高互动内容，提升品牌在跨境电商平台上的竞争力"},
                    {"headline":"AI驱动内容生产提效提质","subheading":"为了提高内容生产的效率与质量，我们积极布局AIGC技术，利用DEEPSEEK大模型等前沿AI工具优化内容创作流程"},
                    {"headline":"AI驱动内容提效与精准度，赋能品牌全球化转型","subheading":"AI技术赋能内容创作，实现高效生产与精准匹配，强化品牌传播效果，助力客户全球数字化转型"},
                    {"headline":"赋能本地企业全球化","subheading":"作为西南跨境电商协会核心成员，为本地企业提供出海支持，助力开拓国际市场"},
                    {"headline":"全链服务赋能西南电商全球化","subheading":"整合资源与政策，提供从市场分析到物流的全链条服务，助力西南电商企业国际化发展，提升竞争力"},
                ]
            data = {
                "images": image_data,
                "description":description
            }

            return api_response(ResponseCode.SUCCESS, "访问成功！", data)
        except Exception as e:
            return api_response(ResponseCode.INTERNAL_SERVER_ERROR, str(e))


#         try:
#             category = kwargs['category']
#             images = ImageModel.objects.filter(category=category)
#             image_data = [{"name": image.name, "url": image.image_path} for image in images]
#
#             data = {}
#             if int(category) == 1:
#                 data = {
#                     "images": image_data,
#                     "headline": "提供TikTok全链路电商解决方案",
#                     "subheading": "专注于TikTok电商的全链路服务，助力品牌在全球市场实现增长",
#                     "description":"""—选品：基于大数据分析的智能选品策略，精准匹配全球市场消费趋势
# —供应链管理：智能供应链管理驱动全球高效交付
# —平台运营：TikTok平台生态的精细化运营策略，实现流量高效转化与品牌价值持续提升，构建良性商业闭环。
# —品牌推广：全域整合营销驱动品牌全球化高效渗透"""
#                 }
#             elif int(category) == 2:
#                 data = {
#                     "images": image_data,
#                     "headline": "数据驱动助力品牌全球高效增长",
#                     "subheading": "通过精准的市场洞察和高效的执行力，帮助品牌在全球市场中快速占领市场实现业绩增长"
#                 }
#             elif int(category) == 3:
#                 data = {
#                     "images": image_data,
#                     "headline": "高质量原创内容驱动品效双增",
#                     "subheading": "自有300平方米专业拍摄中心和先进的内容创作团队，生产高质量原创内容，助力品牌实现社交声量与电商转化的双重增长，构建可持续的内容营销生态"
#                 }
#             elif int(category) == 4:
#                 data = {
#                     "images": image_data,
#                     "headline": "打造高互动性、强传播力的优质内容",
#                     "subheading": "市场趋势+用户洞察的内容创作，打造高互动内容，提升品牌在跨境电商平台上的竞争力"
#                 }
#             elif int(category) == 5:
#                 data = {
#                     "images": image_data,
#                     "headline": "AI驱动内容生产提效提质",
#                     "subheading": "为了提高内容生产的效率与质量，我们积极布局AIGC技术，利用DEEPSEEK大模型等前沿AI工具优化内容创作流程"
#                 }
#             elif int(category) == 6:
#                 data = {
#                     "images": image_data,
#                     "headline": "AI驱动内容提效与精准度，赋能品牌全球化转型",
#                     "subheading": "AI技术赋能内容创作，实现高效生产与精准匹配，强化品牌传播效果，助力客户全球数字化转型"
#                 }
#             elif int(category) == 7:
#                 data = {
#                     "images": image_data,
#                     "headline": "赋能本地企业全球化",
#                     "subheading": "作为西南跨境电商协会核心成员，为本地企业提供出海支持，助力开拓国际市场"
#                 }
#             elif int(category) == 8:
#                 data = {
#                     "images": image_data,
#                     "headline": "全链服务赋能西南电商全球化",
#                     "subheading": "整合资源与政策，提供从市场分析到物流的全链条服务，助力西南电商企业国际化发展，提升竞争力"
#                 }
#
#             return api_response(ResponseCode.SUCCESS, "访问成功！", data)
#         except Exception as e:
#             return api_response(ResponseCode.INTERNAL_SERVER_ERROR, str(e))


class Technology(APIView):
    """
    核心技术
    """

    @swagger_auto_schema(
        operation_description="核心技术，category 传入 2",
        responses={
            200: openapi.Response(
                description="访问成功！",
                schema=openapi.Schema(
                    type=openapi.TYPE_OBJECT,
                    properties={
                        "code": openapi.Schema(type=openapi.TYPE_INTEGER, description="状态码"),
                        "message": openapi.Schema(type=openapi.TYPE_STRING, description="返回信息"),
                        "data": openapi.Schema(
                            type=openapi.TYPE_OBJECT,
                            properties={
                                "images": openapi.Schema(
                                    type=openapi.TYPE_ARRAY,
                                    items=openapi.Schema(
                                        type=openapi.TYPE_OBJECT,
                                        properties={
                                            "name": openapi.Schema(type=openapi.TYPE_STRING, description="图片名称"),
                                            "url": openapi.Schema(type=openapi.TYPE_STRING, description="图片路径"),
                                        }
                                    ),
                                    description="图片列表"
                                ),
                                "headline": openapi.Schema(type=openapi.TYPE_STRING, description="大标题"),
                                "subheading": openapi.Schema(
                                    type=openapi.TYPE_ARRAY,
                                    items=openapi.Schema(type=openapi.TYPE_STRING),
                                    description="小标题列表"
                                ),
                            }
                        )
                    }
                )
            ),
            500: openapi.Response(description="服务器内部错误")
        },
        tags=["核心业务"]
    )
    def get(self, request, **kwargs):
        try:
            category = kwargs['category']
            images = ImageModel.objects.filter(category=category)
            image_data = [{"name": image.name, "url": image.image_path} for image in images]
            data = {
                    "images": image_data,
                    "headline": "四大核心能力",
                    "subheading": ["智能产品研发与市场分析", "全自动短视频剪辑与矩阵发布", "本土化语言模型与AIGC技术", " 智能广告投放与优化"]
                }

            return api_response(ResponseCode.SUCCESS, "访问成功！", data)
        except Exception as e:
            return api_response(ResponseCode.INTERNAL_SERVER_ERROR, str(e))




